#ifndef ACCOUNT_MANAGER_H
#define ACCOUNT_MANAGER_H

#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <openssl/sha.h>
#include <openssl/rand.h>

using namespace std;

class AccountManager {
public:
    struct UserAccount {
        string username;
        string password_hash;
        string salt;
    };

    AccountManager(const string& account_file = "accounts.dat");
    
    bool createAccount(const string& username, const string& password);
    bool authenticate(const string& username, const string& password) const;
    bool accountExists(const string& username) const;
    bool changePassword(const string& username, const string& new_password);
    void saveAccountsToFile() const;
    void loadAccountsFromFile();

private:
    string generateSalt() const;
    string hashPassword(const string& password, const string& salt) const;
    string hexEncode(const unsigned char* data, size_t len) const;

    vector<UserAccount> accounts;
    string account_file_path;
};

#endif